package cn.com.gas.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.gas.mapper.GasJyzxxImportJcxxMapper;
import cn.com.gas.entity.GasJyzxxImportJcxxEntity;
import cn.com.gas.service.GasJyzxxImportJcxxService;
import cn.com.thirdparty.entity.JyzxxImportJcxxEntity;
import cn.com.thirdparty.service.JyzxxImportJcxxService;
import cn.com.util.TsBqUtils;
import lombok.extern.slf4j.Slf4j;


@Service("gasJyzxxImportJcxxService")
@Slf4j
public class GasJyzxxImportJcxxServiceImpl extends ServiceImpl<GasJyzxxImportJcxxMapper, GasJyzxxImportJcxxEntity> implements GasJyzxxImportJcxxService {

	@Autowired
	private JyzxxImportJcxxService jyzxxImportJcxxService;
	
	@Override
	public void saveJcxx(GasJyzxxImportJcxxEntity gasJyzxxImportJcxx) {
		try {
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strDate = sdf.format(date);
			
			gasJyzxxImportJcxx.setId(TsBqUtils.getUUID());
			gasJyzxxImportJcxx.setUpdateTime(strDate);
			
			this.save(gasJyzxxImportJcxx);
			
			JyzxxImportJcxxEntity entity = new JyzxxImportJcxxEntity();
			BeanUtils.copyProperties(gasJyzxxImportJcxx, entity);
			
			// 写入 第三方数据库
			jyzxxImportJcxxService.saveCygxx(entity);
			
		} catch (Exception e) {
			log.error("GasJyzxxImportJcxxServiceImpl.saveJcxx异常:"+e.getMessage());
		}
	}

	@Override
	public void removeByIdsJcxx(List<String> ids) {

		try {
			
			for (String id : ids) {
				this.removeById(id);
				// 写入 第三方数据库
				jyzxxImportJcxxService.removeByIdCygxx(id);
				
			}
		} catch (Exception e) {
			log.error("GasJyzxxImportJcxxServiceImpl.removeByIdsJcxx异常:"+e.getMessage());

		}
	
	}

	@Override
	public void updateByIdJcxx(GasJyzxxImportJcxxEntity gasJyzxxImportJcxx) {

		try {
			
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String strDate = sdf.format(date);
			
			gasJyzxxImportJcxx.setUpdateTime(strDate);
			
			this.updateById(gasJyzxxImportJcxx);
			
			JyzxxImportJcxxEntity entity = new JyzxxImportJcxxEntity();
			BeanUtils.copyProperties(gasJyzxxImportJcxx, entity);
			
			// 写入 第三方数据库
			jyzxxImportJcxxService.updateByIdCygxx(entity);
			
		} catch (Exception e) {
			log.error("GasJyzxxImportJcxxServiceImpl.updateByIdJcxx异常:"+e.getMessage());

		}
	
	}


}